package com.pirestupppai.widgets.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.pirestupppai.R;

/**
 * 列表空视图
 *
 * @author: xiaoluo
 * @date: 2017-04-11 16:49
 */
public class EmptyView extends LinearLayout {
    private Context mContext;

    private TextView mEmptyTv;
    private ImageView mEmptyIv;
    private boolean isShowImage;
    private String mText;

    public EmptyView(Context context) {
        this(context, null);
    }

    public EmptyView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public EmptyView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mContext = context;
        LayoutInflater.from(mContext).inflate(R.layout.view_empty, this, true);
        mEmptyTv = (TextView) this.findViewById(R.id.empty_text);
        mEmptyIv = (ImageView) this.findViewById(R.id.empty_image);

        TypedArray typedArray = mContext.obtainStyledAttributes(attrs, R.styleable.EmptyView);
        mText = typedArray.getString(R.styleable.EmptyView_empty_view_text);
        isShowImage = typedArray.getBoolean(R.styleable.EmptyView_is_show_image, true);

        typedArray.recycle();

        mEmptyTv.setText(mText);
        if (isShowImage) {
            mEmptyIv.setVisibility(VISIBLE);
        } else {
            mEmptyIv.setVisibility(GONE);
        }
    }

    public void setText(String text) {
        mEmptyTv.setText(text);
    }
}
